Public Class ernNetwork
    Private connection As New Net.Sockets.TcpClient
    Private serverName As String = "localhost"

    Public Function getConnection() As Net.Sockets.TcpClient
        Return connection
    End Function

    Public Function getServerName() As String
        Return serverName
    End Function

    Public Sub setServerName(ByVal sn As String)
        serverName = sn
    End Sub

    Public Sub sendFile(ByVal filename As String, Optional ByVal showProgress As Boolean = False)
        Dim file As New IO.FileStream(filename, IO.FileMode.Open, IO.FileAccess.Read)
        Dim binFile As New IO.BinaryReader(file, System.Text.Encoding.ASCII)
        Dim sentFileSize As Integer = 0
        Dim fileBlock() As Byte
        Dim filesize As Integer = New IO.FileInfo(filename).Length
        Dim msg As New protocol

        binFile.BaseStream.Seek(0, IO.SeekOrigin.Begin)
        While sentFileSize < filesize
            ReDim fileBlock(connection.SendBufferSize)
            fileBlock = binFile.ReadBytes(connection.SendBufferSize)
            sentFileSize = sentFileSize + fileBlock.Length
            connection.GetStream.Write(fileBlock, 0, fileBlock.Length)
        End While
        binFile.Close()
        file.Close()
        msg.type = protocolType.A_sendAutoUpdateFileDone
        msg.message = ""
        sendMessage(msg)
        getMessage(msg)
    End Sub

    Public Sub getFile(ByVal filename As String, ByVal size As Integer)
        Dim file As New IO.FileStream(filename, IO.FileMode.OpenOrCreate)
        Dim binFile As New IO.BinaryWriter(file, System.Text.Encoding.ASCII)
        Dim fileSize As Integer = 0
        Dim blockSize As Integer
        Dim fileBlock() As Byte
        Dim msg As New protocol

        While fileSize < size
            ReDim fileBlock(connection.SendBufferSize)
            blockSize = connection.GetStream.Read(fileBlock, 0, connection.SendBufferSize)
            fileSize = fileSize + blockSize
            If fileSize > size Then
                binFile.Write(fileBlock, 0, (blockSize - (fileSize - size)))
            Else
                binFile.Write(fileBlock, 0, blockSize)
            End If
            binFile.BaseStream.Flush()
        End While
        binFile.Close()
        file.Close()
        msg.type = protocolType.SA_sendAutoUpdateFileACK
        msg.message = ""
        sendMessage(msg)
    End Sub

    Public Sub sendMessage(ByVal msg As protocol)
        Dim bytesToSend() As Byte
        ReDim bytesToSend(0)

        If Not msg.message Is Nothing Then
            If msg.message.Length > 1025 Then MsgBox("ERROR: Trying to send message larger than 1024 with message type " & msg.type)
        End If

        bytesToSend = System.Text.Encoding.ASCII.GetBytes(msg.type & ControlChars.NullChar.ToString & msg.message)
        Try
            connection.Client.Send(bytesToSend, bytesToSend.Length, Net.Sockets.SocketFlags.None)
        Catch
            errNetworkSendError(Me, msg)
        End Try
    End Sub

    Public Sub getMessage(ByRef msg As protocol)
        Dim bytesComingIn(1024) As Byte
        Dim size As Integer

        Try
            size = connection.Client.Receive(bytesComingIn)
        Catch
            errNetworkReceiveError(Me, msg)
        End Try
        If size = 0 Then
            errNetworkReceiveError(Me, msg)
        Else
            msg.type = Split(System.Text.Encoding.ASCII.GetString(bytesComingIn), ControlChars.NullChar, 2)(0)
            msg.message = Split(System.Text.Encoding.ASCII.GetString(bytesComingIn), ControlChars.NullChar, 2)(1).Trim(ControlChars.NullChar)
        End If
    End Sub

    Public Sub sendTargetedMessage(ByVal msg As protocol, ByVal target As Net.Sockets.TcpClient)
        Dim bytesToSend() As Byte
        ReDim bytesToSend(0)

        bytesToSend = System.Text.Encoding.ASCII.GetBytes(msg.type & ControlChars.NullChar.ToString & msg.message)
        Try
            target.Client.Send(bytesToSend, bytesToSend.Length, Net.Sockets.SocketFlags.None)
        Catch
            errNetworkSendError(Me, msg)
        End Try
    End Sub

    Public Sub getTargetedMessage(ByRef msg As protocol, ByVal target As Net.Sockets.TcpClient)
        Dim bytesComingIn(0) As Byte
        ReDim bytesComingIn(1024)
        Dim size As Integer

        Try
            size = target.Client.Receive(bytesComingIn)
        Catch
            errNetworkReceiveError(Me, msg)
        End Try
        If size = 0 Then errNetworkReceiveError(Me, msg)
        msg.type = Split(System.Text.Encoding.ASCII.GetString(bytesComingIn), ControlChars.NullChar, 2)(0)
        msg.message = Split(System.Text.Encoding.ASCII.GetString(bytesComingIn), ControlChars.NullChar, 2)(1).Trim(ControlChars.NullChar)
    End Sub

    Private Function generateHandshakeResponse(ByVal i As Integer) As Integer
        generateHandshakeResponse = ((((i * 520 + 1981) / (i / 2)) - i) * 5) Mod 1024
    End Function

    Public Function isConnected() As Boolean
        Return connection.Connected
    End Function

    Public Function hasData() As Boolean
        Return (connection.Available > 0)
    End Function

    Public Class Client
        Inherits ernNetwork
        Public isAdmin As Boolean = False

        Public Sub disconnect()
            connection.Close()
        End Sub

        Public Function connect() As Boolean
            isAdmin = False
            Try
                connection.Connect(serverName, ern_serverPort)
            Catch ex As Exception
                Return False
            End Try
            connection.SendTimeout = 1000 * 30
            connection.ReceiveTimeout = 1000 * 30
            connect = handshake()
        End Function

        Public Function connect(ByVal asAdmin As Boolean) As Boolean
            Try
                If asAdmin Then
                    connection.Connect(serverName, ern_adminPort)
                    isAdmin = True
                Else
                    connection.Connect(serverName, ern_serverPort)
                    isAdmin = False
                End If
            Catch
                Return False
            End Try
            connection.SendTimeout = 1000 * 30
            connection.ReceiveTimeout = 1000 * 30
            connect = handshake()
        End Function

        Private Function handshake() As Boolean
            Dim msg As protocol
            Dim holdit As Integer
            Dim phase1 As Boolean = False
            Dim r As New Random(System.DateTime.Now.Millisecond)
            Dim min As Integer
            Dim max As Integer
            Dim i As Integer

            msg.type = protocolType.C_handshake

            'generate random number
            min = r.Next(102)
            For i = 0 To min
                If (r.Next(102) Mod 2) = 1 Then
                    min = r.Next(102)
                End If
            Next
            max = r.Next(520, 1024)
            For i = 520 To min
                If (r.Next(520, 1024) Mod 2) = 1 Then
                    min = r.Next(102)
                End If
            Next

            i = r.Next(min, max)
            msg.message = i
            sendMessage(msg)
            getMessage(msg)

            holdit = generateHandshakeResponse(i)
            If holdit = msg.message Then phase1 = True

            msg.type = protocolType.C_handshake
            msg.message = generateHandshakeResponse(msg.message)
            sendMessage(msg)
            getMessage(msg)

            handshake = phase1 And msg.message
        End Function

        Public Sub adminBuildComputerTree(ByRef uiObject As Object, Optional ByVal doClients As Boolean = False)
            Dim tempNode As Windows.Forms.TreeNode

            CType(uiObject, Windows.Forms.TreeView).Nodes.Clear()
            tempNode = CType(uiObject, Windows.Forms.TreeView).Nodes.Add("0", "My Network")
            tempNode.ToolTipText = "Base object representing your entire network"
            tempNode.Tag = "0"
            adminBuildComputerTreeBranch(0, uiObject, doClients)
            If doClients Then adminListGroupMembersTree(0, uiObject)
        End Sub

        Private Sub adminBuildComputerTreeBranch(ByVal baseID As Integer, ByRef uiObject As Object, Optional ByVal doClients As Boolean = False)
            Dim msg As protocol
            Dim keys As String
            Dim temps() As String
            Dim names As String
            Dim desc As String
            Dim i As Integer
            Dim tempNode As Windows.Forms.TreeNode

            msg.type = protocolType.A_buildComputerTree
            msg.message = baseID.ToString
            sendMessage(msg)
            getMessage(msg)
            temps = Split(msg.message, ControlChars.NullChar)

            For i = 0 To temps.Length - 1
                If temps(i) <> "" Then
                    keys = temps(i).Substring(0, temps(i).IndexOf(":"))
                    names = temps(i).Substring(temps(i).IndexOf(":") + 1, (temps(i).IndexOf(":", temps(i).IndexOf(":") + 1) - temps(i).IndexOf(":")) - 1)
                    desc = temps(i).Substring(temps(i).IndexOf(":", temps(i).IndexOf(":") + 1) + 1)
                    tempNode = CType(uiObject, Windows.Forms.TreeView).Nodes.Find(baseID.ToString, True)(0).Nodes.Add(keys, names)
                    tempNode.ToolTipText = desc
                    tempNode.Tag = keys
                    adminBuildComputerTreeBranch(keys, uiObject, doClients)
                    If doClients Then adminListGroupMembersTree(keys, uiObject)
                End If
            Next
        End Sub

        Public Sub adminNewGroup(ByVal name As String, ByVal desc As String, ByVal parent As String, ByRef uiObject As Object)
            Dim msg As protocol
            Dim tempNode As Windows.Forms.TreeNode

            msg.message = parent & ":" & name & ":" & desc
            msg.type = protocolType.A_newComputerGroup
            sendMessage(msg)
            getMessage(msg)
            tempNode = CType(uiObject, Windows.Forms.TreeView).Nodes.Find(parent, True)(0).Nodes.Add(msg.message.Trim(ControlChars.NullChar).ToString, name)
            tempNode.ToolTipText = desc
            tempNode.Tag = msg.message.Trim(ControlChars.NullChar).ToString
        End Sub

        Public Sub adminEditGroup(ByVal name As String, ByVal desc As String, ByVal nodeID As String, ByRef uiObject As Object)
            Dim msg As protocol
            Dim tempNode As Windows.Forms.TreeNode

            msg.message = nodeID & ":" & name & ":" & desc
            msg.type = protocolType.A_editComputerGroup
            sendMessage(msg)
            getMessage(msg)
            tempNode = CType(uiObject, Windows.Forms.TreeView).Nodes.Find(nodeID, True)(0)
            tempNode.ToolTipText = desc
            tempNode.Text = name
        End Sub

        Public Sub adminDeleteGroup(ByVal nodeID As Integer, ByRef uiObject As Object)
            Dim msg As protocol
            Dim tempNode As Windows.Forms.TreeNode

            msg.type = protocolType.A_deleteComputerGroup
            msg.message = nodeID
            sendMessage(msg)
            getMessage(msg)
            tempNode = CType(uiObject, Windows.Forms.TreeView).Nodes.Find(nodeID.ToString, True)(0)
            CType(uiObject, Windows.Forms.TreeView).SelectedNode = CType(uiObject, Windows.Forms.TreeView).Nodes.Find(nodeID.ToString, True)(0).Parent
            tempNode.Remove()
        End Sub

        Public Sub adminListGroupMembers(ByVal groupID As Integer, ByRef uiObject As Object)
            Dim msg As protocol
            Dim cDetails() As String
            Dim tempDetails1() As String
            Dim tempDetails2() As String
            Dim tempDetails3() As String
            Dim j, k As Integer

            CType(uiObject, Windows.Forms.DataGridView).Rows.Clear()
            msg.type = protocolType.A_listGroupMembers
            msg.message = groupID.ToString
            sendMessage(msg)
            getMessage(msg)
            While msg.type <> protocolType.SA_listGroupMembersEnd
                cDetails = Split(msg.message, "##")
                j = CType(uiObject, Windows.Forms.DataGridView).Rows.Add()
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(0).Value = cDetails(0)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(1).Value = cDetails(1)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(2).Value = cDetails(2)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Tag = cDetails(3)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(3).Value = cDetails(4)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(4).Value = cDetails(5)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(5).Value = cDetails(6)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(6).Value = cDetails(7)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(7).Value = cDetails(8)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(8).Value = cDetails(9)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(9).Value = cDetails(10)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(10).Value = cDetails(11)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(11).Value = cDetails(12) & " (" & cDetails(13) & ")"
                'CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(11).Value = cDetails(12)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(12).Value = FormatNumber(cDetails(14), 0) & "K / " & FormatNumber(cDetails(15), 0) & "K (" & CType(((cDetails(15) - cDetails(14)) / cDetails(15)) * 100, Integer) & "% Free)"
                'CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(13).Value = cDetails(14)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(13).Value = cDetails(16)
                tempDetails1 = Split(cDetails(17), ":")
                tempDetails2 = Split(cDetails(19), ":")
                tempDetails3 = Split(cDetails(18), ":")
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(14).Value = ""
                For k = 0 To tempDetails1.Length - 1
                    If CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(14).Value = "" Then
                        CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(14).Value = tempDetails1(k) & ": " & FormatNumber(tempDetails2(k), 0) & " (" & tempDetails3(k) & "%)"
                    Else
                        CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(14).Value = CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(14).Value & ControlChars.CrLf & tempDetails1(k) & ": " & FormatNumber(tempDetails2(k), 0) & " (" & tempDetails3(k) & "%)"
                    End If
                Next
                'CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(15).Value = cDetails(16)
                'CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(16).Value = cDetails(17)
                tempDetails1 = Split(cDetails(20), ":")
                tempDetails2 = Split(cDetails(21), ":")
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(15).Value = ""
                'CType(uiObject, Windows.Forms.DataGridView).Rows(j).Height = CType(uiObject, Windows.Forms.DataGridView).Rows(j).Height * tempDetails1.Length
                For k = 0 To tempDetails1.Length - 1
                    If CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(15).Value = "" Then
                        CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(15).Value = tempDetails1(k) & " (" & tempDetails2(k) & ")"
                    Else
                        CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(15).Value = CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(15).Value & ControlChars.CrLf & tempDetails1(k) & " (" & tempDetails2(k) & ")"
                    End If
                Next
                'CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(14).Value = cDetails(19) & " (" & cDetails(20) & ")"
                'CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(18).Value = cDetails(19)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(16).Value = cDetails(22) & " (" & FormatNumber(cDetails(23), 0) & " threads)"
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(17).Value = cDetails(24)
                CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(18).Value = cDetails(25)
                'CType(uiObject, Windows.Forms.DataGridView).Rows(j).Cells(20).Value = cDetails(21)
                msg.message = "ok"
                msg.type = protocolType.A_listGroupMembers
                sendMessage(msg)
                getMessage(msg)
            End While
        End Sub

        Public Function adminGetClientDetails(ByVal clientID As String) As String()
            Dim msg As protocol
            Dim cDetails() As String

            msg.type = protocolType.A_getClientDetails
            msg.message = clientID
            sendMessage(msg)
            getMessage(msg)
            If msg.type = protocolType.SA_clientDetails Then
                cDetails = Split(msg.message, "##")
                Return cDetails
            Else
                Return Nothing
            End If
        End Function

        Public Sub adminListGroupMembersTree(ByVal groupID As Integer, ByRef uiObject As Object)
            Dim msg As protocol
            Dim cDetails() As String
            Dim node As Windows.Forms.TreeNode

            msg.type = protocolType.A_listGroupMembers
            msg.message = groupID.ToString
            sendMessage(msg)
            getMessage(msg)
            While msg.type <> protocolType.SA_listGroupMembersEnd
                cDetails = Split(msg.message, "##")
                node = CType(uiObject, Windows.Forms.TreeView).Nodes.Find(groupID, True)(0).Nodes.Add(cDetails(3), cDetails(0))
                node.Tag = cDetails(3)
                
                msg.message = "ok"
                msg.type = protocolType.A_listGroupMembers
                sendMessage(msg)
                getMessage(msg)
            End While
        End Sub

        Public Sub adminChangeComputerGroup(ByVal computerIDs As String, ByVal newGroupID As String)
            Dim msg As protocol

            msg.type = protocolType.A_changeComputerGroup
            msg.message = computerIDs & ":" & newGroupID
            sendMessage(msg)
            getMessage(msg)
        End Sub

        Public Sub adminRenameComputers(ByVal oldNewNames As String)
            Dim msg As protocol

            msg.type = protocolType.A_renameComputers
            msg.message = oldNewNames
            sendMessage(msg)
            getMessage(msg)
        End Sub

        Public Function adminGetPolicyDetails(ByVal groupID As Integer) As policyType
            Dim policy As policyType
            Dim msg As protocol
            Dim msgParts() As String

            msg.type = protocolType.A_getPolicy
            msg.message = groupID
            sendMessage(msg)
            getMessage(msg)

            msgParts = Split(msg.message, "::")
            With policy
                .id = msgParts(0)
                .name = msgParts(1)
                .checkInTime = msgParts(2)
                .rebootPolicy.everyFewMinutes = msgParts(3)
                .rebootPolicy.time1 = msgParts(4)
                .rebootPolicy.useTime1 = msgParts(5)
                .rebootPolicy.time2 = msgParts(6)
                .rebootPolicy.useTime2 = msgParts(7)
                .rebootPolicy.time3 = msgParts(8)
                .rebootPolicy.useTime3 = msgParts(9)
                .rebootPolicy.rebootSchedule = msgParts(10)
                .rebootPolicy.scheduledRebootDay = msgParts(11)
                .auPolicy.enabled = msgParts(12)
                .auPolicy.day = msgParts(13)
                .auPolicy.time = msgParts(14)
            End With

            Return policy
        End Function

    End Class

    Public Class Server
        Inherits ernNetwork
        Sub New(ByRef conn As Net.Sockets.TcpClient)
            connection = conn
            connection.SendTimeout = 1000 * 30
            connection.ReceiveTimeout = 1000 * 30
        End Sub

        Public Function handshake() As Boolean
            Dim msg As protocol
            Dim holdit As Integer
            Dim phase1 As Boolean = False

            msg.type = protocolType.BLANK
            msg.message = ""
            getMessage(msg)
            msg.type = protocolType.S_handshake
            holdit = generateHandshakeResponse(msg.message)
            msg.message = holdit
            sendMessage(msg)
            getMessage(msg)
            If generateHandshakeResponse(holdit) = msg.message Then phase1 = True
            msg.type = protocolType.S_handshake
            msg.message = phase1
            sendMessage(msg)

            handshake = phase1
        End Function

        Public Function renameClient(ByVal newName As String) As Boolean
            Dim msg As protocol

            msg.type = protocolType.S_renameClient
            msg.message = newName
            sendMessage(msg)
            getMessage(msg)

            If msg.message = "0" Then Return True Else Return False
        End Function
    End Class
End Class

Public Enum protocolType
    'blank used just for giving the message some value
    BLANK = 0

    'used for admin client to server communications
    A_buildComputerTree = 3001
    A_newComputerGroup = 3002
    A_deleteComputerGroup = 3003
    A_editComputerGroup = 3004
    A_listGroupMembers = 3005
    A_changeComputerGroup = 3006
    A_renameComputers = 3007
    A_getPolicy = 3008
    A_setPolicy = 3009
    A_forceClientReboot = 3010
    A_heartbeat = 3011
    A_newAutoUpdateInfo = 3012
    A_sendAutoUpdateFile = 3013
    A_sendAutoUpdateFileDone = 3014
    A_editAutoUpdateInfo = 3015
    A_startAutoUpdateList = 3016
    A_getAutoUpdateItem = 3017
    A_startAUInstallList = 3018
    A_getAUInstallItem = 3019
    A_deleteAUItem = 3020
    A_setAUPublishDefaults = 3021
    A_getAUPublishDefaults = 3022
    A_applyPolicyToGroup = 3023
    A_getClientDetails = 3024

    'used for server to admin client communications
    SA_ERROR = 4000
    SA_buildComputerTree = 4001
    SA_newComputerGroup = 4002
    SA_deleteComputerGroup = 4003
    SA_editComputerGroup = 4004
    SA_listGroupMembersItem = 4005
    SA_changeComputerGroup = 4006
    SA_renameComputers = 4007
    SA_getPolicy = 4008
    SA_setPolicy = 4009
    SA_forcedClientReboot = 4010
    SA_heartbeat = 4011
    SA_newAutoUpdateID = 4012
    SA_sendAutoUpdateFileACK = 4013
    SA_editAutoUpdateInfoACK = 4014
    SA_autoUpdateItem = 4015
    SA_endAutoUpdateList = 4016
    SA_AUInstallItem = 4017
    SA_endAUInstallList = 4018
    SA_deletedAUItem = 4019
    SA_sendAUPublishDefaults = 4020
    SA_listGroupMembersEnd = 4021
    SA_applyPolicyToGroup = 4022
    SA_clientDetails = 4023

    'used for all client to server communications
    C_handshake = 1001
    C_computerName = 1002
    C_checkIn = 1003
    C_checkInOK = 1004
    C_getPolicy = 1005
    C_rebootReminder = 1006
    C_renameClient = 1007
    C_scheduledRebootReminder = 1008
    C_forcedClientReboot = 1009
    C_heartbeat = 1010
    C_downloadAU = 1011
    C_clientUpdated = 1012

    'used for all server to client communications
    S_ERROR = 2000
    S_handshake = 2001
    S_policy = 2002
    S_checkIn = 2003
    S_checkInOK = 2004
    S_rebootReminder = 2005
    S_renameClient = 2006
    S_scheduledRebootReminder = 2007
    S_forceClientReboot = 2008
    S_heartbeat = 2009
    S_sendAU = 2010
    S_clientUpdatedOK = 2011
End Enum

Public Structure protocol
    Dim type As protocolType
    Dim message As String
End Structure

Public Structure policyType
    Dim name As String
    Dim id As Integer
    Dim checkInTime As Integer
    Dim rebootPolicy As rebootPolicyType
    Dim auPolicy As auPolicyType
End Structure

Public Structure auPolicyType
    Dim enabled As Boolean
    Dim day As Integer
    Dim time As String
End Structure

Public Structure rebootPolicyType
    Dim time1 As Date
    Dim useTime1 As Boolean
    Dim time2 As Date
    Dim useTime2 As Boolean
    Dim time3 As Date
    Dim useTime3 As Boolean
    Dim everyFewMinutes As Integer
    Dim rebootSchedule As rebootScheduleType
    Dim scheduledRebootDay As Integer
End Structure

Public Enum rebootScheduleType
    threeTimesADay = 1
    everyFewMinutes = 2
End Enum